package cn.tsingyu.antsclub.controller;

import java.util.Date;
import java.util.Random;

import com.jfinal.core.Controller;
import com.taobao.api.ApiException;
import com.taobao.api.DefaultTaobaoClient;
import com.taobao.api.TaobaoClient;
import com.taobao.api.request.AlibabaAliqinFcSmsNumSendRequest;
import com.taobao.api.response.AlibabaAliqinFcSmsNumSendResponse;

public class MessageController extends Controller {
	public static void main(String[] args) {
		  //官网的URL---必须是这个
        String url="http://gw.api.taobao.com/router/rest"; 

        //成为开发者，创建应用后系统会自动生成
        String appkey="xxxx"; 

        //创建应用后系统会自动生成
        String secret="xxx";

        //随机生成 num 位验证码
        String code="";
        Random r = new Random(new Date().getTime());
        for(int i=0;i<4;i++){
            code = code+r.nextInt(10);
        }
        //需要log4j的Jar包--日志-可删

        //将验证码加入容器中---用户输入验证码之后验证
        //request.getSession().setAttribute("messageCode", code);

		TaobaoClient client = new DefaultTaobaoClient(url, appkey, secret);
		AlibabaAliqinFcSmsNumSendRequest req = new AlibabaAliqinFcSmsNumSendRequest();
		req.setExtend("123456");
		req.setSmsType("normal");
		req.setSmsFreeSignName("精羽门");
		req.setSmsParamString("{\"code\":\""+code+"\"}");
		req.setRecNum("15950014490");
		req.setSmsTemplateCode("SMS_25475390");
		AlibabaAliqinFcSmsNumSendResponse rsp;
		try {
			rsp = client.execute(req);
			System.out.println(rsp.getBody());
		} catch (ApiException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
	}
}
